package demo.exception;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/8-08-08-16:16
 * @Description：demo.exception
 */
public class Exception_return {
    public static void methodA() throws Exception {
        try {
            //try中抛出异常，finally会吞掉异常，会先执行finally中的语句，再抛异常
            System.out.println("进入方法A");   //1
            throw new Exception("制造异常");    //3
            //手动抛出异常
        } finally {
            System.out.println("用A方法的finally");    //2
        }
    }
    public static int methodB() {
        try {
            //try中如果有return，finally也有return，finally执行到return后不会跳回去
            System.out.println("进入方法B");    //1
            return 1;
        } finally {
            System.out.println("用B方法的finally");   //2
            return 2;                             //3   方法结束
        }
    }
    public static void main(String[] args) {
        try {
            methodA();


        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        int i = methodB();
        System.out.println(i);    //2
        //进入方法A
        //用A方法的finally
        //制造异常
        //进入方法B
        //用B方法的finally
        //2
    }
}
